import sys
import pylab as plt
import os
from params import *
from plotter import *

date = '2010-08-18'
file = os.path.join(WORKDIR, 'gowalla', 'stats',
    'gowalla_all_checkins_%s.txt'%date)
print file
print "Stamps date ", date

place_per_user = {}
user_per_place = {}
checkins_per_user = {}
checkins_per_place = {}
for line in open(file):
    user,place,num = map(int,line.split(','))

    if not user in place_per_user:
        place_per_user[user] = set()
    place_per_user[user].add(place)

    if not place in user_per_place:
        user_per_place[place] = set()
    user_per_place[place].add(user)

    if not user in checkins_per_user:
        checkins_per_user[user] = 0
    checkins_per_user[user] += num

    if not place in checkins_per_place:
        checkins_per_place[place] = 0
    checkins_per_place[place] += num

print 'read values'

def plot(data,name,f,**kwargs):
    values = []
    for v in data:
        values.append(f(data[v]))
    p = Plotter(values)
    p.fit_plot(name,**kwargs)

plot(checkins_per_user,'gowalla_dist_checkin_user',lambda x:x,log=False)
plot(place_per_user,'gowalla_dist_place_user',len,log=False)
#plot(user_per_place,'dist_user_place_%s'%date,len,t1=10,t2=100)
#plot(checkins_per_place,'dist_checkin_place_%s'%date,lambda x:x,t1=10,t2=100)
